001 /*
002 * Copyright 1996-2005 Mort Bay Consulting Pty. Ltd.
003 * Copyright 2006 Stephen McConnell.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package net.dpml.test.http;
019
020 import java.io.IOException;
021
022 import javax.servlet.ServletConfig;
023 import javax.servlet.ServletException;
024 import javax.servlet.ServletOutputStream;
025 import javax.servlet.http.HttpServlet;
026 import javax.servlet.http.HttpServletRequest;
027 import javax.servlet.http.HttpServletResponse;
028
029
030 /**
031 * Hello World Servlet
032 */
033 public class HelloWorld extends HttpServlet
034 {
035 /**
036 * Servlet initialization.
037 * @param config the servlet configuration
038 * @exception ServletException if a configuration error occurs
039 */
040 public void init( ServletConfig config ) throws ServletException
041 {
042 super.init( config );
043 }
044
045 /**
046 * Process an incomming post request.
047 * @param request the http request
048 * @param response the http response
049 * @exception ServletException if a servlet processing error occurs
050 * @exception IOException if an IO error occurs
051 */
052 public void doPost( HttpServletRequest request, HttpServletResponse response )
053 throws ServletException, IOException
054 {
055 doGet( request, response );
056 }
057
058 /**
059 * Process an incomming get request.
060 * @param request the http request
061 * @param response the http response
062 * @exception ServletException if a servlet processing error occurs
063 * @exception IOException if an IO error occurs
064 */
065 public void doGet( HttpServletRequest request, HttpServletResponse response )
066 throws ServletException, IOException
067 {
068 response.setContentType( "text/html" );
069 ServletOutputStream out = response.getOutputStream();
070 out.println( "<html>" );
071 out.println( "<h1>Hello World<h1>" );
072 out.println( "</html>" );
073 out.flush();
074 }
075 }